using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// Git 触发规则实体
/// </summary>
[Table(Name = "git_trigger_rules")]
public class GitTriggerRule
{
    /// <summary>
    /// 规则 ID
    /// </summary>
    [Column(IsPrimary = true, IsIdentity = true)]
    public long Id { get; set; }

    /// <summary>
    /// 关联的工作流 ID
    /// </summary>
    [Column(IsNullable = false)]
    public long WorkflowId { get; set; }

    /// <summary>
    /// 规则名称
    /// </summary>
    [Column(StringLength = 200, IsNullable = false)]
    public string Name { get; set; } = null!;

    /// <summary>
    /// 触发类型：Push, Tag, PullRequest, Manual
    /// </summary>
    [Column(StringLength = 50, IsNullable = false)]
    public string TriggerType { get; set; } = null!;

    /// <summary>
    /// 分支匹配规则（正则表达式）
    /// 例如：^(main|master)$、^release/.*$
    /// </summary>
    [Column(StringLength = 500)]
    public string? BranchPattern { get; set; }

    /// <summary>
    /// Tag 匹配规则（正则表达式）
    /// 例如：^v\d+\.\d+\.\d+$
    /// </summary>
    [Column(StringLength = 500)]
    public string? TagPattern { get; set; }

    /// <summary>
    /// 路径过滤规则（多个路径用逗号分隔）
    /// 例如：src/**,docs/**
    /// </summary>
    [Column(StringLength = 1000)]
    public string? PathFilter { get; set; }

    /// <summary>
    /// 是否启用
    /// </summary>
    [Column(IsNullable = false)]
    public bool IsEnabled { get; set; } = true;

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column(IsNullable = false)]
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 创建者
    /// </summary>
    [Column(StringLength = 100)]
    public string? CreatedBy { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdatedAt { get; set; }

    /// <summary>
    /// 关联的工作流定义
    /// </summary>
    [Navigate(nameof(WorkflowId))]
    public WorkflowDefinition? Workflow { get; set; }
}
